import { Injectable } from '@angular/core'
import { AgentFull } from '@shared/interfaces/group'
import { ObservableStore } from '@shared/classes/ObservableStoreClass'
import { deepCopy } from '@delon/util'

@Injectable()
export class GroupStoreService extends ObservableStore<AgentFull> {

  constructor() {
    super(new AgentFull())
  }

  updateValue(agentFull: AgentFull): void {
    /* 将传入的 group 和旧的 group 进行合并,注意多级嵌套 */
    const value = deepCopy(this.value)
    Object.assign(value, agentFull)
    this.setValue(value)
  }

  reset(): void {
    this.setValue(new AgentFull())
  }
}
